package com.shelpe.services.tenant.proxy;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;


@FeignClient(name="${simbaproxy.serviceID}", url="${simbaproxy.url}")
@RequestMapping(value = "/simba")
public interface MessageServiceClient {
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.tmc.user.permit")
	public PermitResponse permitMessage(@RequestHeader("tenantID") long userId, @RequestParam("topics") String topics);
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.tmc.user.cancel")
	public CancelResponse cancelMessage(@RequestParam("nick") String nick);
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.tmc.messages.consume")
	public ConsumeMessageResponse consumeMessage(@RequestHeader("tenantID") long userId);
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.tmc.messages.confirm")
	public ConfirmMessageResponse confirmMessage(@RequestHeader("tenantID") long userId, @RequestParam("s_message_ids") String ids);
	
	@Data
	public static class PermitResponse extends SimbaProxyBaseDto{
		
		@JsonProperty("tmc_user_permit_response")
		private StatusRes res;
	}
	
	@Data
	public static class CancelResponse extends SimbaProxyBaseDto{
		
		@JsonProperty("tmc_user_cancel_response")
		private StatusRes res;
	}
	
	@Data
	public static class ConsumeMessageResponse extends SimbaProxyBaseDto{
		
		@JsonProperty("tmc_messages_consume_response")
		private ConsumeRes res;
	}
	
	public static class ConfirmMessageResponse extends SimbaProxyBaseDto{
		
		@JsonProperty("tmc_messages_confirm_response")
		private StatusRes res;
	}
	
	@Data
	public static class StatusRes{
		
		@JsonProperty("is_success")
		private Boolean isSuccess;
	}
	
	@Data
	public static class ConsumeRes{
		
		@JsonProperty("messages")
		private ConsumeMessages messages;
	}
	
	@Data
	public static class ConsumeMessages{
		
		@JsonProperty("tmc_message")
		private List<TmcMessage> tmcList;
	}
	
	@Data
	public static class TmcMessage{
		
		  private Long id; //"id":123456789,
		  private String topic; //"topic":"TradeCreate",
		  @JsonProperty("pub_app_key")
          private String appKey; //"pub_app_key":"45671234",
		  @JsonProperty("pub_time")		
		  private String pubTime; //"pub_time":"2000-01-01 00:00:00",
		  @JsonProperty("user_nick")
          private String nick; //"user_nick":"helloworld",
          private String content; //"content":"{\"tid\":2895732958732,\"seller_nick\":\"helloworld\"}",
          @JsonProperty("user_id")
          private Long userId; //"user_id":12345
          
	}

}
